home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '92 / Hacks ’92 / Procedure Call Logger / BP_EP.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-02  |  3.9 KB  |  163 lines  |  [TEXT/MPS ]

  1. /*
  2.     These are routines called by the %_BP and %_EP routines in
  3.     BP_EP.a. Those routines replace the ones in the library,
  4.     and enable the user to implement their own debugger.
  5.     
  6.     Author:    Marshall Clow
  7.     
  8.     Log:
  9.         Jun 02, 1992    new file.
  10. */
  11.  
  12. #include "BP_EP.h"
  13.  
  14. #include <Memory.h>
  15.  
  16.  
  17. /*    Override this procedure to control breaking into the debugger */
  18. #pragma trace off
  19. Boolean    BreakHere ( void ) {
  20.     return false;
  21.     }
  22.  
  23.  
  24. #pragma trace off
  25. Boolean    IsValidSymbolChar ( char ch ) {
  26.     if ( ch >= 'A' && ch <= 'Z' )
  27.         return true;
  28.     if ( ch >= 'a' && ch <= 'z' )
  29.         return true;
  30.     if ( ch >= '0' && ch <= '9' )
  31.         return true;
  32.     return ch == '_' || ch == '%' || ch == ' ';
  33.     }
  34.  
  35.  
  36. /*
  37.     From DisAsmLookup.h:
  38.     A valid MacsBug symbol consists of the characters '_', '%', spaces, digits, and
  39.     upper/lower case letters in a format determined by the first two bytes of the
  40.     symbol as follows:
  41.     
  42.        1st byte  | 2nd byte  |  Byte  |
  43.          Range   |  Range    | Length | Comments
  44.       ==============================================================================
  45. (1)       $20 - $7F | $20 - $7F |    8   | "Old style" MacsBug symbol format
  46.        $A0 - $FF | $20 - $7F |    8   | "Old style" MacsBug symbol format
  47.       ------------------------------------------------------------------------------
  48. (2)       $20 - $7F | $80 - $FF |   16   | "Old style" MacApp symbol ab==>b.a
  49.        $A0 - $FF | $80 - $FF |   16   | "Old style" MacApp symbol ab==>b.a
  50.       ------------------------------------------------------------------------------
  51. (3)       $80       | $01 - $FF |    n   | n = 2nd byte       (Apple Compiler symbol)
  52. (4)       $81 - $9F | $00 - $FF |    m   | m = 1st byte & $7F (Apple Compiler symbol)
  53.       ==============================================================================
  54. */
  55.  
  56. enum {
  57.     kStyleUndef,
  58.     kStyle8,
  59.     kStyle16,
  60.     kStyle80,
  61.     kStyle81Up
  62.     };
  63.     
  64. typedef unsigned short TMacsBugStyles;
  65.     
  66. #pragma trace off
  67. Boolean IsMacsBugName ( void *theCode, Str255 theName ) {
  68.     TMacsBugStyles    theStyle = kStyleUndef;
  69.     Ptr                codePtr = theCode;
  70.     unsigned char    firstChar = *codePtr;
  71.     unsigned char    secondChar = codePtr [ 1 ];
  72.     short            i, length;
  73.     
  74.     
  75. /*    Identify the type of Symbol */
  76.     if ( firstChar == 0x80 )
  77.         theStyle = kStyle80;
  78.     else if ( firstChar > 0x80 && firstChar < 0xA0 )
  79.         theStyle = kStyle81Up;
  80.     else
  81.         theStyle = secondChar >= 0x80 && secondChar <= 0xFF ? kStyle16 : kStyle8;
  82.     
  83.     if ( theStyle == kStyleUndef )
  84.         return false;
  85.         
  86. /*    Build the Symbol */
  87.     switch ( theStyle ) {
  88.         case kStyle8:
  89.             BlockMove ( codePtr, theName + 1, 8 );
  90.             theName [ 0 ] = 8;
  91.             theName [ 1 ] &= 0x7F;
  92.             break;
  93.             
  94.         case kStyle16:
  95.             theName [ 0 ] = 17;
  96.             theName [ 9 ] = '%';
  97.             BlockMove ( codePtr,     theName + 10, 8 );
  98.             BlockMove ( codePtr + 8, theName +  1, 8 );
  99.             theName [  1 ] &= 0x7F;
  100.             theName [ 10 ] &= 0x7F;
  101.             break;
  102.             
  103.         case kStyle80:
  104.             BlockMove ( codePtr + 1, theName, codePtr [ 1 ] );
  105.             break;
  106.             
  107.         case kStyle81Up:
  108.             length = *codePtr & 0x7F;
  109.             BlockMove ( codePtr, theName, length + 1 );
  110.             theName [ 0 ] = length;
  111.             break;
  112.             
  113.         default:
  114.             DebugStr ( "\pBad Style" );
  115.             break;
  116.             }
  117.     
  118.     i = theStyle;
  119.     for ( i = 1; i <= theName [ 0 ]; i++ )
  120.         if ( !IsValidSymbolChar ( theName [ i ] ))
  121.             return false;
  122.     return true;
  123.     }
  124.  
  125.  
  126. /*
  127.     Also From DisAsmLookup.h:
  128.     Check to see if the specified memory address, contains a RTS, JMP (A0) or
  129.     RTD #n instruction immediately followed by a valid MacsBug symbol.  These
  130.     sequences are the only ones which can determine an end of module when MacsBug
  131.     symbols are present.
  132. */
  133.     
  134. #define    kRTS            0x4E75
  135. #define    kJMPA0            0x4ED0
  136. #define    kRTDn            0x4E74
  137. #define    kMaxModuleWords    0x0400
  138.  
  139. #pragma trace off
  140. Boolean    FindMacsBugName ( void *theCode, Str255 theName ) {
  141.     short *codePtr = theCode;
  142.     short *limitPtr = codePtr + kMaxModuleWords;
  143.     
  144.     while ( codePtr < limitPtr ) {
  145.         switch ( *codePtr ) {
  146.             case kRTDn:
  147.                 codePtr++;
  148.             case kRTS:
  149.             case kJMPA0:
  150.                 codePtr++;
  151.                 if ( IsMacsBugName ( codePtr, theName ))
  152.                     return true;
  153.                 
  154.             default:
  155.                 break;
  156.             }
  157.             
  158.         codePtr++;
  159.         }
  160.     
  161.     return false;
  162.     }
  163.